#ifndef __MCS__CONDITION__HPP
#define __MCS__CONDITION__HPP

#include "Expression.hpp"
#include "TypeMismatchException.hpp"
#include "RunTimeException.hpp"

class Condition
{
public:
	Condition(ptr<Expression> cond)
		: expression_(cond) 
	{}

	void init(Block * parentBlock)
	{
		expression_->init(parentBlock);

		Value::DataType type = expression_->dataType();
		if(type != Value::Bool)
		{
			throw TypeMismatchExcepion(type, Value::Bool, expression_->location());
		}
	}

	bool check() const
	{
		ptr<Value> val = expression_->evaluate();
		ptr<BoolValue> bval = val.dynamicCast<BoolValue>();
		MCSC_ASSERT(bval);
		return bval->value();
	}
private:
	ptr<Expression> expression_;
};

#endif //__MCS__CONDITION__HPP
